package org.shiki.hrm.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;

//@Component
public class BaseFeignAuthorInterceptor implements RequestInterceptor {
	@Override
	public void apply(RequestTemplate requestTemplate) {
		// 获取原来请求中的token
		ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.currentRequestAttributes();
		HttpServletRequest request = requestAttributes.getRequest();
		String authorization = request.getHeader("Authorization");
		// 设置到feign发起的请求中
		requestTemplate.header("Authorization", authorization);
	}
}
